Fix route simplifier to not remove one too many points in edge cases.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 21 Sep 2014 23:04:22 +0000 (23:04 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 21 Sep 2014 23:04:22 +0000 (23:04 +0000)
Fix from Steve.

gpsbabel/smplrout.cc

index 34dc8f6a77a9cd0e24641669e3998b4a477ff56a..f402c5a04847631b5fd24da0aa0bd368157eb6cb 100644 (file)
@@ -319,6 +319,15 @@ routesimple_tail(const route_head* rte)
   for (i = 0; i < xte_count; i++) {
     xte_recs[i].intermed->xte_rec = xte_recs+i;
   }
+  // Ensure totalerror starts with the distance between first and second points
+  // and not the zero-init.  From a June 25, 2014  thread titled "Simplify 
+  // Filter: GPSBabel removes one trackpoint..."  I never could repro it it
+  // with the sample data, so there is no automated test case, but Steve's 
+  // fix is "obviously" right here.
+  if (xte_count >= 1) {
+    totalerror = xte_recs[xte_count-1].distance;
+  }
+
   /* while we still have too many records... */
   while ((xte_count) && ((countopt && count < xte_count) || (erroropt && totalerror < error))) {
     i = xte_count - 1;